package java_thinking.unit_18_IO._18_1;

import java.util.Arrays;
import java.util.Collection;

/**
 * @Desc:   可以添加新行并缩排所有元素的工具
 * @author: cww
 * @DateTime: 2019-05-12 17:09
 */

public class PPrint {
    public static String pformat(Collection<?> c) {
        if (c.size() == 0) {
            return "[]";
        }
        StringBuilder builder = new StringBuilder("[");
        for (Object o : c) {
            if (c.size() != 1) {
                builder.append("\n ");
            }
            builder.append(o);
        }
        if (c.size() != 1) {
            builder.append("\n");
        }
        builder.append("]");
        return builder.toString();
    }
    public static void pprint(Collection<?> c) {
        System.out.println(pformat(c));
    }
    public static void pptint(Object[] c) {
        System.out.println(pformat(Arrays.asList(c)));
    }
}
